package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.PurchaseListGoodsService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.Map;

/**
 * @description 进货商品Controller层
 */
@RestController
public class PurchaseListGoodsController {

    @Autowired
    PurchaseListGoodsService purchaseListGoodsService;

    /**
     * 分页查询供应商
     * @param page
     * @param rows
     * @param
     * @return
     */
    @PostMapping("/supplier/list")
    public Map<String,Object> supplierList(@PathParam("page") Integer page,
                                           @PathParam("rows") Integer rows,
                                           String supplierName){
//        String supplierName = null;
        PageInfo<Supplier> supplierList = purchaseListGoodsService.supplierList(page,rows,supplierName);
        Map<String,Object> map = new HashMap<>();
        map.put("total",supplierList.getTotal());
        map.put("rows",supplierList.getList());
        return map;
    }

    /**
     * 添加或者修改供应商
     * @return
     */
    @PostMapping("/supplier/save")
    public ServiceVO<Supplier> saveOrUpdata(
            @RequestParam(value = "supplierId",required = false) Integer supplierId,
                                            Supplier supplier){
        if(supplierId != null){
            //修改
            purchaseListGoodsService.updataSupplier(supplierId,supplier);
        }else{
            //添加
            purchaseListGoodsService.addSupplier(supplier);
        }

        return  new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 删除供应商
     * @param ids
     * @return
     */
    @PostMapping("/supplier/delete")
    public ServiceVO removeSupplier(String ids){
        purchaseListGoodsService.removeSupplier(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

















/*
    @Autowired
    private PurchaseListGoodsService purchaseListGoodsService;

    *//**
     * 保存进货单信息
     * @param purchaseList 进货单信息实体
     * @param purchaseListGoodsStr 进货商品信息JSON字符串
     * @return
     *//*
    @RequestMapping("/save")
    @RequiresPermissions(value = "进货入库")
    public ServiceVO save(PurchaseList purchaseList, String purchaseListGoodsStr) {
        return purchaseListGoodsService.save(purchaseList, purchaseListGoodsStr);
    }

    *//**
     * 查询进货单
     * @param purchaseNumber 单号
     * @param supplierId 供应商ID
     * @param state 付款状态
     * @param sTime 开始时间
     * @param eTime 结束时间
     * @return
     *//*
    @RequestMapping("/list")
    @RequiresPermissions(value={"进货单据查询","供应商统计"},logical = Logical.OR)
    public Map<String,Object> list(String purchaseNumber, Integer supplierId, Integer state, String sTime,
                                   String eTime) {
        return  purchaseListGoodsService.list(purchaseNumber, supplierId, state, sTime, eTime);
    }

    *//**
     * 查询进货单商品信息
     * @param purchaseListId 进货单ID
     * @return
     *//*
    @RequestMapping("/goodsList")
    @RequiresPermissions(value={"进货单据查询","供应商统计"},logical = Logical.OR)
    public Map<String, Object> goodsList(Integer purchaseListId) {
        return purchaseListGoodsService.goodsList(purchaseListId);
    }

    *//**
     * 删除进货单及商品信息
     * @param purchaseListId 进货单ID
     * @return
     *//*
    @RequestMapping("/delete")
    @RequiresPermissions(value = "进货单据查询")
    public ServiceVO delete(Integer purchaseListId) {
        return purchaseListGoodsService.delete(purchaseListId);
    }

    *//**
     * 修改进货单付款状态
     * @param purchaseListId 进货单ID
     * @return
     *//*
    @RequestMapping("/updateState")
    @RequiresPermissions(value = "供应商统计")
    public ServiceVO updateState(Integer purchaseListId) {
        return purchaseListGoodsService.updateState(purchaseListId);
    }

    *//**
     * 进货商品统计
     * @param sTime 开始时间
     * @param eTime 结束时间
     * @param goodsTypeId 商品类别ID
     * @param codeOrName 编号或商品名称
     * @return
     *//*
    @RequestMapping("/count")
    @RequiresPermissions(value = "商品采购统计")
    public String count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName) {
        return purchaseListGoodsService.count(sTime, eTime, goodsTypeId, codeOrName);
    }*/

}
